<template>
    <div class="e-form">
        <BillTop title="自有台账详情" @cancel="handleClose"></BillTop>
        <div class="tabs warningTabs">
            <el-tabs tab-position="left" v-model="tabsName" @tab-click="onChangeTab">
                <!-- 基本信息 -->
                <el-tab-pane label="基本信息" name="baseInfo" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="进出场记录" name="entryExitRecords" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="维修保养记录" name="maintenanceRecords" :disabled="clickTabFlag"></el-tab-pane>
                <el-tab-pane label="其他" name="other" :disabled="clickTabFlag"></el-tab-pane>
                <div>
                    <div id="baseInfoCon" class="con">
                        <div class="tabs-title" id="baseInfo">基本信息</div>
                        <div style="width: 100%" class="form">
                            <el-form ref="form" :model="formData.accountOwn" label-width="200px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="设备编号：">
                                            <span>{{ formData.accountOwn.equipmentNo }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="二维码：">
                                            <el-image style="width:100px;height:100px" :src="formData.accountOwn.codePicture"></el-image>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="原始编号：">
                                            <span>{{ formData.accountOwn.originalNo }}</span>
                                        </el-form-item>
                                    </el-col>
                                     <el-col :span="12">
                                        <el-form-item label="设备类别：">
                                            <span>{{ formData.accountOwn.categoryName }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="设备名称：">
                                            <span>{{ formData.accountOwn.equipmentName }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="所属机构：">
                                            <span>{{ formData.accountOwn.orgName }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="规格型号：">
                                            <span>{{ formData.accountOwn.specificationModel }}</span>
                                        </el-form-item>
                                    </el-col>
                                     <el-col :span="12">
                                        <el-form-item label="使用单位：">
                                            <span>{{ formData.accountOwn.useOrgName  }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="计量单位：">
                                            <span>{{ formData.accountOwn.unit }}</span>
                                        </el-form-item>
                                    </el-col>
                                     <el-col :span="12">
                                        <el-form-item label="验收地点：">
                                            <span>{{showAddress(formData.accountOwn.acceptanceSite)}}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="验收日期：">
                                            <span>{{ formData.accountOwn.billDate }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="生产厂商：">
                                            <span>{{ formData.accountOwn.menufacturer }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="验收单号：">
                                            <span>{{ formData.accountOwn.billNo }}</span>
                                        </el-form-item>
                                    </el-col>
                                     <el-col :span="12">
                                        <el-form-item label="原厂编号：">
                                            <span>{{ formData.accountOwn.productionNo }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="出厂日期：">
                                            <span>{{ formData.accountOwn.productionDate }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="车牌编号：">
                                            <span>{{ formData.accountOwn.plateNo }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="设备属性：">
                                            <span>{{ formData.accountOwn.nature !== "" || formData.accountOwn.nature !== null ? deviceProperties.find(x=>x.value === formData.accountOwn.nature).label:'' }}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="购置日期：">
                                            <span>{{ formData.accountOwn.purchaseDate }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="台账状态：">
                                            <span>{{ formData.accountOwn.accountState !== "" || formData.accountOwn.accountState !== null ? accountStatus.find(x=>x.value == formData.accountOwn.accountState).label :''}}</span>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="设备状态：">
                                            <span>{{   formData.accountOwn.equipmentState !== "" || formData.accountOwn.equipmentState !== null? equipStatus.find(x=>x.value == formData.accountOwn.equipmentState).label:''  }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>

                                    <el-col :span="12">
                                        <el-form-item label="设备状况：">
                                            <span>{{ formData.accountOwn.equipmentCondition !== "" || formData.accountOwn.equipmentCondition !== null ? equipCondition.find(x=>x.value == formData.accountOwn.equipmentCondition).label : '' }}</span>
                                        </el-form-item>
                                    </el-col>
                                     <el-col :span="12">
                                        <el-form-item label="操作手：">
                                            <span>{{ formData.accountOwn.operatorName }}</span>
                                        </el-form-item>
                                    </el-col>
                                </el-row>

                            </el-form>
                        </div>
                    </div>

                    <div id="entryExitRecordsCon" class="con">
                        <div class="tabs-title" id="entryExitRecords">进出场记录</div>
                        <div class="e-table">
                            <div class="top">
                                <div class="left">
                                    <div>
                                        <el-button  class="btn-greenYellow" @click="addPlanInfo">新增</el-button>
                                        <el-button  class="btn-delete" @click="deletePlanList" v-if="isBatch.flag">批量删除</el-button>
                                    </div>
                                    <div class="batchBox" @click="batchOperation">
                                        <img class="batchicon" src="@/assets/piliang.png">
                                        <span class="batchfont">{{isBatch.batch}}</span>
                                    </div>
                                </div>
                            </div>
                            <div class="errorMsg" v-if="errorMsg.length>0">
                                <span v-for="item,index in errorMsg" :key="index">
                                    {{item}}
                                </span>
                            </div>
                            <el-table
                                :max-height="$store.state.tableHeight"
                                class="table"
                                ref="planTable"
                                :data="accessRecordListCopy"
                                border
                                style="width: 100%"
                                @selection-change="planTableSelect"
                                v-sortTable="{ 'tableData': accessRecordListCopy, '_this': this, 'ref': 'planTable' }"
                            >
                                <el-table-column type="selection" width="55" align="center" v-if="isBatch.flag">
                                </el-table-column>
                                <el-table-column  fixed type="index" label="序号" width="80" align="center">
                                </el-table-column>
                                <el-table-column fixed label="操作" width="70">
                                    <template slot-scope="{ row,$index }">
                                        <div class="handle">
                                            <div style=" cursor: pointer;">
                                                <img src="@/assets/btn/delete.png"  @click="handleDelete(row,$index)">
                                            </div>
                                        </div>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="useOrg"
                                    label="使用单位"
                                    align="center"
                                    min-width="200"
                                    show-overflow-tooltip
                                >
                                    <template slot-scope="{ row }">
                                        <el-input v-model="row.useOrg"  readonly>
                                            <i slot="suffix" class="el-input__icon el-icon-document-copy" @click="selectUseOrg(row)"></i>
                                        </el-input>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="enterDate"
                                    label="进场时间"
                                    width="170"
                                    align="center"
                                >
                                    <template slot-scope="{ row }">
                                        <el-date-picker
                                            v-model="row.enterDate"
                                            type="date"
                                            placeholder="选择日期"
                                            value-format="yyyy-MM-dd"
                                            :clearable="false"
                                            @input="curStateChange(row)"
                                        >
                                        </el-date-picker>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="retreatDate"
                                    label="退场时间"
                                    width="170"
                                    align="center"
                                >
                                    <template slot-scope="{ row }">
                                        <el-date-picker
                                            v-model="row.retreatDate"
                                            type="date"
                                            placeholder="选择日期"
                                            value-format="yyyy-MM-dd"
                                            :clearable="false"
                                            @input="curStateChange(row)"
                                        >
                                        </el-date-picker>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>

                    <div id="maintenanceRecordsCon" class="con">
                        <div class="tabs-title" id="maintenanceRecords">维修保养记录</div>
                        <div class="e-table">
                            <el-table
                                :max-height="$store.state.tableHeight"
                                class="table"
                                ref="planTable"
                                :data="maintenanceLogList"
                                border
                                style="width: 100%"
                                v-sortTable="{ 'tableData': maintenanceLogList, '_this': this, 'ref': 'maintenanceRecords' }"
                            >
                                <el-table-column
                                    prop="maintenanceUnit"
                                    label="维保单位"
                                    align="center"
                                    min-width="200"
                                    show-overflow-tooltip
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="maintenanceType"
                                    label="维保类型"
                                    width="150"
                                    align="center"
                                >
                                    <template slot-scope="{ row }">
                                        <span>{{ row.maintenanceType?maintenanceType[row.maintenanceType].label:'' }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="sendToRepairTime"
                                    label="送修/养时间"
                                    width="170"
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="completeRepairTime"
                                    label="完修/养时间"
                                    width="170"
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="manpowerPrice"
                                    label="人工费（元）"
                                    width="130"
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="materialsPrice"
                                    label="材料费（元）"
                                    width="130"
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="equipmentPrice"
                                    label="设备费（元）"
                                    width="130"
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="maintenancePrice"
                                    label="维保费（元）"
                                    width="130"
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="maintenanceDetails"
                                    label="维修内容"
                                    min-width="150"
                                    show-overflow-tooltip
                                    align="center"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>

                    <div id="otherCon" class="con">
                        <div class="tabs-title" id="other">其他</div>
                        <div class="e-table">
                            <el-table
                                :max-height="$store.state.tableHeight"
                                class="table"
                                ref="planTable"
                                border
                                style="width: 100%"
                                :data="otherTable"
                                v-sortTable="{ 'tableData': otherTable, '_this': this, 'ref': 'other' }"
                            >
                                <el-table-column
                                    prop="title"
                                    label="标题"
                                    align="center"
                                    min-width="200"
                                    show-overflow-tooltip
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="type"
                                    label="类型"
                                    width="200"
                                    align="center"
                                >
                                    <template slot-scope="{ row }">
                                        <span>{{ row.type?otherType[row.type].label:'' }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="generalSituation"
                                    label="概况"
                                    width="200"
                                    show-overflow-tooltip
                                    align="center"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="billDate"
                                    label="填报日期"
                                    width="200"
                                    align="center"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                </div>
            </el-tabs>
        </div>
        <div class="buttons">
            <el-button type="primary" size="small" class="btn-blue" v-debounce
                >打印</el-button
            >
            <el-button type="primary" size="small" class="btn-blue" v-debounce
                >打印二维码</el-button
            >
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                >保存进出场记录</el-button>
            <el-button size="small" @click="handleClose" v-debounce>取消</el-button>
        </div>
        <div id="seat" :style="{height: seatHeight + 'px'}"></div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
import $ from 'jquery'
import request from '@/api/equip/equipAccount.js'
import '@/utils/jquery.scrollTo.min'
import { selectUseUnit } from '@/api/equip/popupCallback.js'
import { hideLoading, showLoading } from '@/utils/common'
export default {
    data () {
        return {
            isBatch: {
                flag: true,
                batch: '进入批量管理'
            },
            tabsName: 'baseInfo',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            formData: {
                //基础信息
                'accountOwn': {
                    'acceptanceSite': '',
                    'accountStatus': '',
                    'addStatus': '',
                    'billDate': '',
                    'billId': '',
                    'billNo': '',
                    'categoryId': '',
                    'categoryName': '',
                    'depreciationCount': 0,
                    'easId': '',
                    'equipmentCondition': '',
                    'equipmentId': '',
                    'equipmentName': '',
                    'equipmentNo': '',
                    'equipmentStatus': '',
                    'equipmentUnitId': '',
                    'equipmentUnitName': '',
                    'isMaintenance': '',
                    'logId': '',
                    'managementOrgId': '',
                    'managementOrgName': '',
                    'menufacturer': '',
                    'nature': '',
                    'netWorth': 0,
                    'oneLevelCategoryId': '',
                    'oneLevelCategoryName': '',
                    'operatorId': '',
                    'operatorName': '',
                    'orgId': '',
                    'orgName': '',
                    'originalNo': '',
                    'ownAccountId': '',
                    'plateNo': '',
                    'productionDate': '',
                    'productionNo': '',
                    'purchaseDate': '',
                    'purchasePrice': 0,
                    'serviceLife': 0,
                    'specificationModel': '',
                    'stipulatedServiceLife': 0,
                    'unit': '',
                    'useOrgId': '',
                    'useOrgName': '',
                    'useageTime': 0
                },
            },
            billid: this.$route.query.billid,
            planSelect: [], //固定资产盘点明细选择项
            accessRecordList: [], //进出场记录
            accessRecordListCopy: [],
            maintenanceLogList: [], //维保记录表格
            otherTable: [], //其他表格
            workIndex: 0,
            errorList: [], //控制导航栏感叹号的显示
            errorMsg: [], //计划明细错误显示
            isErrorMsg: true, //是否提醒错误信息
            currentRow: {},
        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.contract.ctClassify.currencyForm, //币种
            equipStatus: state => state.equip.equipData.equipStatus, //设备状态
            timeUnitList: state => state.equip.equipData.timeUnitList, //计时单位
            useType: state => state.equip.equipData.useType, //计时单位
            measurementMode: state => state.equip.equipData.measurementMode, //计量方式
            maintenanceType: state => state.equip.equipData.maintenanceType, //维保类型
            equipCondition: state => state.equip.equipData.equipCondition, //设备状况
            deviceProperties: state => state.equip.equipData.deviceProperties, //设备属性
            otherType: state => state.equip.equipData.otherType, //其他类型
            accountStatus: state => state.equip.equipData.accountStatus, //台账状态
        }),
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>x.value === param)
                return obj.label
            }
        },
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 72 - this.lastConHeight
        },
        showAddress () {
            return value=>{
                if(!value) return ''
                const obj = JSON.parse(value)
                const address = obj.address ? obj.address.join('-') : ''
                const detail = obj.detail
                let str = ''
                if(address && detail) {
                    str = address + '-' + detail
                }else if(!address  && detail) {
                    str = detail
                }else if(address  && !detail) {
                    str = address
                }
                return str
            }
        }
    },
    components: {
    },
    watch: {
        //给错误标签加上提醒
        errorList: newData=>{
            const tabs = document.querySelectorAll('.el-tabs__item')
            tabs.forEach(DOM=>{
                const { childNodes } = DOM
                if(childNodes.length > 1) {
                    DOM.removeChild(childNodes[1])
                }
            })
            newData.forEach(item=>{
                const itemDom = document.querySelector(`#tab-${item}`)
                var element = document.createElement('i')
                element.className = 'el-icon-warning-outline warning'
                itemDom.appendChild(element)
            })
        },
    },
    created () {
        this.userId = localStorage.getItem('userId')
        this.getDicValue()
        this.init()
    },
    mounted () {
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()

        // 保存所有tabName
        const arr = ['baseInfo', 'maintenanceRecords', 'entryExitRecords', 'other']
        this.tabArr = arr
        let $idsTop = []
        window.addEventListener('scroll', () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }

            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    console.log('item', item)
                    const itemTop = document.getElementById(item).offsetTop
                    return itemTop
                })
            }
            const scrollTop = document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if ((scrollTop + 1) >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        })

        this.screenWidth = document.documentElement.clientWidth - this.topHeight
        this.screenHeight = document.documentElement.clientHeight - this.topHeight
        window.addEventListener('resize', () => {
            this.screenWidth = document.documentElement.clientWidth - this.topHeight
            this.screenHeight = document.documentElement.clientHeight - this.topHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        })

    },
    methods: {
        //获取当前使用的字典
        getDicValue () {
            this.$store.dispatch('equip/setTimeUnitList')//更新计时单位
            this.$store.dispatch('equip/setUseType')//更新使用类型
            this.$store.dispatch('equip/setMeasurementMode')//更新计量方式
            this.$store.dispatch('equip/setRunningState')//更新运行状态
            this.$store.dispatch('equip/setMaintenanceType')//更新维保类型
            this.$store.dispatch('equip/setEquipStatus')//更新设备状态
        },
        //是否进入批量操作
        batchOperation () {
            this.isBatch.flag = !this.isBatch.flag
            if(this.isBatch.flag) {
                this.isBatch.batch = '退出批量管理'
                this.$refs.planTable.clearSelection()
            }else{
                this.isBatch.batch = '进入批量管理'
            }
        },
        init () {
            showLoading()
            Promise.all([
                this.getInfo(),
                this.getPlanList(),
                this.getMaintenanceRecord(),
                this.getOther(),
            ]).finally(() => {
                hideLoading()
            })
        },
        //基本信息查询
        getInfo () {
            const params = {
                id: this.billid,
            }
            request.ownAccountBaseInfo(params).then(res=>{
                this.formData = res
            })
        },
        //进出场记录查询
        getPlanList () {
            const params = {
                id: this.billid,
            }
            request.getEntryExitRecords(params).then(res=>{
                this.accessRecordListCopy = []
                this.accessRecordList = res
                res.map(item=>{
                    this.accessRecordListCopy.push(item)
                })
            })
        },
        //自有台账维修保养记录查询
        getMaintenanceRecord () {
            request.getMaintenanceRecords({ id: this.billid }).then(res=>{
                this.maintenanceLogList = res
            })
        },
        //其他
        getOther () {
            request.getOwnOther({ id: this.billid }).then(res=>{
                this.otherTable = res.data == null ? [] : res
            })
        },
        getNowDate () {
            this.$set(
                this.formData,
                'applyTime',
                new Date()
                    .toLocaleDateString()
                    .replace(new RegExp('/', 'g'), '-')
            )
        },
        //=============================进场验收============================================
        //判断当前状态是否已修改
        curStateChange (row) {
            this.currentRow = row
            if (row.accessRecordId) {
                this.currentRow.changeType = 2
            }
        },
        /**新增 */
        addPlanInfo () {
            const obj = {
                'accessRecordId': '',
                'accountId': this.billid,
                'enterDate': '',
                'retreatDate': '',
                'useOrg': '',
                'useOrgId': '',
                'changeType': 1
            }
            this.accessRecordList.push(obj)
            this.accessRecordListCopy.push(obj)
        },
        //选择使用单位
        selectUseOrg (row) {
            let ids = row.useOrgId ? [row.useOrgId] : []
            selectUseUnit(ids).then(res=>{
                row.useOrg = res[0].outerName
                row.useOrgId = res[0].id
                if(row.accessRecordId) {
                    row.changeType = 2
                }
            })
        },
        //单个明细表格删除
        handleDelete (row, $index) {
            this.clientPop('info', this.oneDeleteErr, ()=>{
                let length = this.errorMsg.length
                this.accessRecordListCopy.splice($index, 1)
                if(row.accessRecordId) {
                    this.$set(this.accessRecordList[$index], 'changeType', -1)
                }else{
                    this.accessRecordList.splice($index, 1)
                }
                if (length > 0 ) {
                    this.verifyTable()
                }
            })
        },
        //获取明细表格的选择项
        planTableSelect (selection) {
            this.planSelect = selection
        },
        //删除明细列表
        deletePlanList () {
            const length = this.planSelect.length
            if(length === 0) {
                this.clientPop(
                    'info',
                    '你还未选择数据,请选择!',
                )
            }else{
                this.clientPop(
                    'info',
                    this.moreDeleteErr(length),
                    this.delete
                )
            }
        },
        delete () {
            this.planSelect.filter(row=>{
                this.accessRecordListCopy.map((x, index)=>{
                    if(row == x ) {
                        this.accessRecordListCopy.splice(index, 1)
                    }
                })
                if(row.accessRecordId) {
                    const index = this.accessRecordList.findIndex(item=>{
                        return item.accessRecordId == row.accessRecordId
                    })
                    this.$set(this.accessRecordList[index], 'changeType', -1)
                }else{
                    this.accessRecordList.map((x, index)=>{
                        if(row == x ) {
                            this.accessRecordList.splice(index, 1)
                        }
                    })
                }
                if (length > 0 ) {
                    this.verifyTable()
                }
                this.$refs.planTable.clearSelection()
            })
        },
        //计划明细非空验证
        verifyTable () {
            return  new Promise((resolve, reject)=>{
                this.errorMsg = []
                this.accessRecordListCopy.forEach((item, index)=>{
                    if(item.changeType !== -1) {
                        if(item.useOrg === null || item.useOrg === '') {
                            let str = `请选择第 ${index + 1} 行的（使用单位）`
                            this.errorMsg.push(str)
                        }
                        if(item.enterDate === null || item.enterDate === '') {
                            let str = `请选择第 ${index + 1} 行的（进场时间）`
                            this.errorMsg.push(str)
                        }
                        if(item.enterDate !== '' || item.enterDate !== null) {
                            const enterDate = new Date(item.enterDate).getTime() //进场时间
                            const retreatDate = new Date(item.retreatDate).getTime() //退场时间
                            if(enterDate > retreatDate) {
                                let str = `第 ${index + 1} 行的（退场时间不能小于进场时间）`
                                this.errorMsg.push(str)
                            }
                        }
                    }
                })
                this.errorMsg.length > 0 ? reject() : resolve()
            })

        },
        //保存进出场记录
        preserve () {
            return new Promise((resolve, reject)=>{
                this.verifyTable().then(()=>{
                    request.setEntryExitRecords(this.accessRecordList).then(()=>{
                        this.clientPop('suc', '保存成功')
                    })
                }).catch(err=>{
                    this.setError('entryExitRecords')
                    reject(err)
                    this.scorllError()
                })
            })
        },
        //取消
        handleClose () {
            this.$router.replace('/ownAccountList')
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('recodesCon')) {
                    const lastConHeight = document.getElementById('recodesCon').offsetHeight
                    console.log('lastConHeight: ', lastConHeight)
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        onChangeTab (e) {
            const height  = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        //设置错误标签
        setError (name) {
            if(!this.errorList.find(x=>x === name)) {
                this.errorList.push(name)
            }
        },
        //跳转到第一个错误标签
        scorllError () {
            let num = this.tabArr.length
            this.errorList.forEach(item=>{
                let index = this.tabArr.findIndex(x=>x === item)
                num = index < num ? index : num
            })
            const obj = { name: this.tabArr[num] }
            this.tabsName = this.tabArr[num]
            this.onChangeTab(obj)
        },
    }
}
</script>

<style lang="scss" scoped>
.form {
    margin-top: 10px;
}

.e-table {
    background: #fff;
}

</style>
